package com.shanks.home.net;

import java.util.concurrent.ConcurrentHashMap;

@SuppressWarnings("serial")
public class SocketByteHashMap extends ConcurrentHashMap<Byte, Object> {
	private String 	m_strCharset = "utf-8";
	
	/***************设置字段值*******************/
	//设置8个字节整型值
	public void putLong(Byte index, long value){
		Long obj = Long.valueOf(value);
		super.put(index, obj);	
	}
	
	//设置4字节整型值
	public void putInt(Byte index, int value){
		Integer obj = Integer.valueOf(value);
		super.put(index, obj);
	}
	public void putInt(Byte index, long value){
		putLong(index, value);
	}	
	public void putInt(Byte index, short value){
		putShort(index, value);
	}	
	public void putInt(Byte index, byte value){
		putByte(index, value);
	}		
	
	//设置2字节整型值
	public void putShort(Byte index, short value){
		
		Short obj = new Short(value);
		
		super.put(index, obj);
	}
	
	//设置1字节整型值
	public void putByte(Byte index, byte value){
		Byte obj = new Byte(value);
		super.put(index, obj);
	}
	
	
	
	//设置字符串值
	public void putString(Byte index, byte[] value) {		
		try{
			String obj = "";

			if (value != null)
				obj = new String(value, m_strCharset);
			super.put(index, obj);
		}
		catch (Exception e) {

			e.printStackTrace();
		}
	}
	
	public void putString(Byte index, byte[] value, int offset, int count) {		
		try{
			String obj = new String(value, offset, count, m_strCharset);
			super.put(index, obj);
		}
		catch (Exception e) {
	
			e.printStackTrace();
		}
	}	
	
	/***************设置字段值*******************/
	
	/***************获取字段值*******************/
	//获取1字节值
	public byte getByte(Byte index){
		Byte obj = (Byte)super.get(index);
		if (obj == null)
			return 0;
		
		return obj.byteValue();		
	}
	
	//获取2字节值
	/**
	 * @param index
	 * @return
	 */
	public short getShort(Byte index){
		Short obj = (Short)super.get(index);
		if (obj == null)
			return 0;
		
		return obj.shortValue();
	}
	
	//获取4字节值
	public int getInt(Byte index){
		Integer obj = (Integer)super.get(index);
		if (obj == null)
			return 0;
		
		return obj.intValue();		
	}	
	
	//获取8字节值
	public long getLong(Byte index){
		Long obj = (Long)super.get(index);
		if (obj == null)
			return 0;
		
		return obj.longValue();
	}		
	
	//获取字符串值
	public String getString(Byte index){
		String obj = super.get(index).toString();
		
		return obj;
	}
	
	/***************获取字段值*******************/
}
